package com.th.supcom.pds.impl.service.internal.phamapply;

import java.util.List;

import net.carefx.framework.exception.BusinessException;
import net.carefx.framework.translate.TranslatorManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.domain.pojo.InpPhamApplyDetail;
import com.th.supcom.pds.domain.pojo.InpPhamApplyDetailSummary;
import com.th.supcom.pds.domain.vo.InpPhamApplyDetailVO;
import com.th.supcom.pds.impl.manager.InpPhamApplyDetailManager;
import com.th.supcom.pds.internal.api.phamapply.InpPhamApplyDetailBasicService;
import com.th.supcom.pds.internal.api.phamapply.PhamApplyService;

public class InpPhamApplyDetailBasicServiceImpl implements InpPhamApplyDetailBasicService
{
    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (InpPhamApplyDetailBasicServiceImpl.class);
    private InpPhamApplyDetailManager m_inpPhamApplyDetailManager;
    private PhamApplyService m_phamApplyService;
    private TranslatorManager m_translatorManager;
    
    public void setPhamApplyService (PhamApplyService phamApplyService)
    {
        m_phamApplyService = phamApplyService;
    }

    public void setTranslatorManager (TranslatorManager translatorManager)
    {
        m_translatorManager = translatorManager;
    }

    public void setInpPhamApplyDetailManager (InpPhamApplyDetailManager inpPhamApplyDetailManager)
    {
        m_inpPhamApplyDetailManager = inpPhamApplyDetailManager;
    }

    @Override
    public InpPhamApplyDetail getInpPhamApplyDetailByID (Long id)
    {
        s_logger.info ("调用getInpPhamApplyDetailByID参数 ：id:{}", new Object[]
        { id });
        if (null == id)
        {
            s_logger.error ("通过主键查询请领单详情表时，主键不能为空");
            throw new IllegalArgumentException ("通过主键查询请领单详情表时，主键不能为空");
        }
        try
        {
            InpPhamApplyDetail inpPhamApplyDetail = m_inpPhamApplyDetailManager.getInpPhamApplyDetailByID (id);
            inpPhamApplyDetail = m_translatorManager.translate (inpPhamApplyDetail);
            return inpPhamApplyDetail;
        }
        catch (Exception e)
        {
            s_logger.error ("通过主键查询请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new IllegalArgumentException ("通过主键查询请领单详情表异常", e);
        }
    }

    @Override
    public List <InpPhamApplyDetailVO> findInpPhamApplyDetailListByExample (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用findInpPhamApplyDetailListByExample参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("通过条件查询请领单详情表时，条件对象不能为空");
            throw new IllegalArgumentException ("通过条件查询请领单详情表时，条件对象不能为空");
        }
        try
        {
            List <InpPhamApplyDetailVO> list = m_inpPhamApplyDetailManager.findInpPhamApplyDetailListByExample (inpPhamApplyDetail);
            list = m_translatorManager.translate (list);
            return list;
        }
        catch (Exception e)
        {
            s_logger.error ("通过条件查询请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new IllegalArgumentException ("通过条件查询请领单详情表异常", e);
        }
    }

    @Override
    public List <InpPhamApplyDetail> getDrugReturnIndicator (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用getDrugReturnIndicator参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("通过药品请领数据查询药品不可退标志时，条件对象不能为空");
            throw new IllegalArgumentException ("通过药品请领数据查询药品不可退标志时，条件对象不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.getDrugReturnIndicator (inpPhamApplyDetail);
        }
        catch (Exception e)
        {
            s_logger.error ("通过药品请领数据查询药品不可退标志时" + e.getLocalizedMessage (), e);
            throw new IllegalArgumentException ("通过药品请领数据查询药品不可退标志时异常", e);
        }
    }

    @Override
    public int findInpPhamApplyDetailCountByExample (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用findInpPhamApplyDetailCountByExample参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("通过条件查询请领单详情表记录数时，条件对象不能为空");
            throw new IllegalArgumentException ("通过条件查询请领单详情表记录数时，条件对象不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.findInpPhamApplyDetailCountByExample (inpPhamApplyDetail);
        }
        catch (Exception e)
        {
            s_logger.error ("通过条件查询请领单详情表记录数异常" + e.getLocalizedMessage (), e);
            throw new IllegalArgumentException ("通过条件查询请领单详情表记录数异常", e);
        }
    }

    @Override
    public int modifyInpPhamApplyDetail (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用modifyInpPhamApplyDetail参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("更新请领单详情表时，对象不能为空");
            throw new IllegalArgumentException ("更新请领单详情表时，对象不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.modifyInpPhamApplyDetail (inpPhamApplyDetail);
        }
        catch (Exception e)
        {
            s_logger.error ("更新请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("更新请领单详情表异常", e);
        }
    }

    @Override
    public int modifyInpPhamApplyDetailByExample (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用modifyInpPhamApplyDetailByExample参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("更新请领单详情表时，对象不能为空");
            throw new IllegalArgumentException ("更新请领单详情表时，对象不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.modifyInpPhamApplyDetailByExample (inpPhamApplyDetail);
        }
        catch (Exception e)
        {
            s_logger.error ("更新请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("更新请领单详情表异常", e);
        }
    }

    @Override
    public void addInpPhamApplyDetail (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用addInpPhamApplyDetail参数 ：inpPhamApplyDetail:{}", new Object[]
        { inpPhamApplyDetail });
        if (null == inpPhamApplyDetail)
        {
            s_logger.error ("添加请领单详情表时，对象不能为空");
            throw new IllegalArgumentException ("添加请领单详情表时，对象不能为空");
        }
        try
        {
            m_inpPhamApplyDetailManager.addInpPhamApplyDetail (inpPhamApplyDetail);
        }
        catch (Exception e)
        {
            s_logger.error ("添加请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("添加请领单详情表异常", e);
        }
    }

    @Override
    public int removeInpPhamApplyDetailByID (Long id)
    {
        s_logger.info ("调用removeInpPhamApplyDetailByID参数 ：id:{}", new Object[]
        { id });
        if (null == id)
        {
            s_logger.error ("通过主键删除请领单详情表时，主键不能为空");
            throw new IllegalArgumentException ("通过主键删除请领单详情表时，主键不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.removeInpPhamApplyDetailByID (id);
        }
        catch (Exception e)
        {
            s_logger.error ("通过主键删除请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("通过主键删除请领单详情表异常", e);
        }
    }

    @Override
    public void addInpPhamApplyDetailList (List <InpPhamApplyDetail> list)
    {
        s_logger.info ("调用addInpPhamApplyDetailList参数 ：list:{}", new Object[]
        { list });
        if (list.isEmpty ())
        {
            s_logger.error ("批量添加请领单详情表时，对象不能为空");
            throw new IllegalArgumentException ("批量添加请领单详情表时，对象不能为空");
        }
        try
        {
            m_inpPhamApplyDetailManager.addInpPhamApplyDetailList (list);
        }
        catch (Exception e)
        {
            s_logger.error ("批量添加请领单详情表异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("批量添加请领单详情表异常", e);
        }
    }

    @Override
    public List <InpPhamApplyDetailVO> findOffsetPhamListSummary (List <InpPhamApplyDetailSummary> list)
    {
        s_logger.info ("调用findOffsetPhamListSummary参数 ：list:{}", new Object[]
        { list });
        if (null == list)
        {
            s_logger.error ("查询护理单元可冲抵药品汇总时，查询条件不能为空");
            throw new IllegalArgumentException ("查询护理单元可冲抵药品汇总时，查询条件不能为空");
        }
        try
        {
            return m_phamApplyService.getOffsetPhamSummaryList (list);
        }
        catch (Exception e)
        {
            s_logger.error ("查询护理单元可冲抵药品汇总异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("查询护理单元可冲抵药品汇总异常", e);
        }
    }

    @Override
    public List <InpPhamApplyDetailVO> findOffsetPhamList (List <InpPhamApplyDetailSummary> list)
    {
        s_logger.info ("调用findOffsetPhamList参数 ：list:{}", new Object[]
        { list });
        if (null == list)
        {
            s_logger.error ("查询护理单元可冲抵药品明细时，查询条件不能为空");
            throw new IllegalArgumentException ("查询护理单元可冲抵药品明细时，查询条件不能为空");
        }
        try
        {
            return m_phamApplyService.getOffsetPhamList (list);
        }
        catch (Exception e)
        {
            s_logger.error ("查询护理单元可冲抵药品明细异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("查询护理单元可冲抵药品明细异常", e);
        }
    }

    @Override
    public int modifyInpPhamApplyDetailList (List <InpPhamApplyDetail> list)
    {
        s_logger.info ("调用modifyInpPhamApplyDetailList参数 ：list:{}", new Object[]
        { list });
        if (null == list)
        {
            s_logger.error ("通过主键ID批量更新表记录，更新对象不能为空");
            throw new IllegalArgumentException ("通过主键ID批量更新表记录，更新对象不能为空");
        }
        try
        {
            return m_inpPhamApplyDetailManager.modifyInpPhamApplyDetailList (list);
        }
        catch (Exception e)
        {
            s_logger.error ("通过主键ID批量更新表记录异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("通过主键ID批量更新表记录异常", e);
        }
    }

    @Override
    public String findPhamUnitByPhamStdCode (String phamStdCode)
    {
        s_logger.info ("调用findPhamUnitByPhamStdCode参数 ：phamStdCode:{}", new Object[]
        { phamStdCode });
        if (null == phamStdCode)
        {
            s_logger.error ("通过药品编码查询药品单位时，药品编码不能为空");
            throw new IllegalArgumentException ("通过药品编码查询药品单位时，药品编码不能为空");
        }
        try
        {
            String phamUnit = m_inpPhamApplyDetailManager.findPhamUnitByPhamStdCode (phamStdCode);
            return phamUnit;
        }
        catch (Exception e)
        {
            s_logger.error ("通过药品编码查询药品单位异常" + e.getLocalizedMessage (), e);
            throw new BusinessException ("通过药品编码查询药品单位异常", e);
        }
    }

    @Override
    public List <InpPhamApplyDetail> findInpPhamApplyDetailForReturn (InpPhamApplyDetailVO inpPhamApplyDetailVO)
    {
        s_logger.info ("调用findInpPhamApplyDetailForReturn参数 ：inpPhamApplyDetailVO:{}", new Object[]
        { inpPhamApplyDetailVO });
        if (null == inpPhamApplyDetailVO)
        {
            s_logger.error ("通过患者流水号ID列表 、请领执行科室、申请单号查询请领明细,对象不能为空");
            throw new IllegalArgumentException ("通过患者流水号ID列表 、请领执行科室、申请单号查询请领明细,对象不能为空");
        }
        try
        {
            List <InpPhamApplyDetail> inpDetail = m_inpPhamApplyDetailManager.findInpPhamApplyDetailForReturn (inpPhamApplyDetailVO);
            inpDetail = m_translatorManager.translate (inpDetail);
            return inpDetail;
        }
        catch (Exception e)
        {
            s_logger.error ("通过患者流水号ID列表 、请领执行科室、申请单号查询请领明细发生异常！" + e.getLocalizedMessage (), e);
            throw new BusinessException ("通过患者流水号ID列表 、请领执行科室、申请单号查询请领明细异常", e);
        }
    }

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, XuNuo Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    @Override
    public List <InpPhamApplyDetailVO> findInpPhamApplyDetailListByCondition (InpPhamApplyDetail inpPhamApplyDetail)
    {
        s_logger.info ("调用findInpPhamApplyDetailListByCondition参数 ：inpPhamApplyDetail:{}", new Object[]
                { inpPhamApplyDetail });
                if (null == inpPhamApplyDetail)
                {
                    s_logger.error ("通过条件查询请领单详情表时，条件对象不能为空");
                    throw new IllegalArgumentException ("通过条件查询请领单详情表时，条件对象不能为空");
                }
                try
                {
                    List <InpPhamApplyDetailVO> list = m_inpPhamApplyDetailManager.findInpPhamApplyDetailListCondition (inpPhamApplyDetail);
                    list = m_translatorManager.translate (list);
                    return list;
                }
                catch (Exception e)
                {
                    s_logger.error ("通过条件查询请领单详情表异常" + e.getLocalizedMessage (), e);
                    throw new IllegalArgumentException ("通过条件查询请领单详情表异常", e);
                }
         
    }

    @Override
    public List <InpPhamApplyDetailVO> findInpPhamApplyCancelListByCondition (InpPhamApplyDetailVO inpPhamApplyDetailVO)
    {
        s_logger.info ("调用findInpPhamApplyCancelListByCondition参数 ：inpPhamApplyDetail:{}", new Object[]
                { inpPhamApplyDetailVO });
                if (null == inpPhamApplyDetailVO)
                {
                    s_logger.error ("通过条件查询请领单详情表时，条件对象不能为空");
                    throw new IllegalArgumentException ("通过条件查询请领单详情表时，条件对象不能为空");
                }
                try
                {
                    List <InpPhamApplyDetailVO> list = m_inpPhamApplyDetailManager.findInpPhamApplyCancelListByCondition (inpPhamApplyDetailVO);
                    list = m_translatorManager.translate (list);
                    return list;
                }
                catch (Exception e)
                {
                    s_logger.error ("通过条件查询请领单详情表异常" + e.getLocalizedMessage (), e);
                    throw new IllegalArgumentException ("通过条件查询请领单详情表异常", e);
                }
         
    }

    @Override
    public List <InpPhamApplyDetailVO> findOffsetPhamByNurseUnitCode (List <InpPhamApplyDetailSummary> list)
    {
        // TODO Auto-generated method stub
        return null;
    }

}
